package com.zhima.controller.plain;

import com.zhima.annotation.MustLogin;
import com.zhima.dto.ZhimaOjResult;
import com.zhima.service.OjUserQuestionService;
import com.zhima.util.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.zhima.dto.ZhimaOjResult.success;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhima
 * @since 2023-08-25
 */
@RestController
@RequestMapping("/user-question")
@MustLogin
public class OjUserQuestionController {
    @Autowired
    private OjUserQuestionService ojUserQuestionService;

    /**
     * 分页返回登录用户的做题记录
     *
     * @param pageNum
     * @param pageSize * @return
     */
    @GetMapping("/{pageNum}/{pageSize}")
    public ZhimaOjResult pageQueryUserQuestion(@PathVariable("pageNum") Long pageNum, @PathVariable("pageSize") Long pageSize) {
        return success(ojUserQuestionService.pageQueryUserQuestion(UserHolder.get().getId(), pageNum, pageSize));
    }

    /**
     * 获得根据题目难度划分的ACmap
     *
     * @return
     */
    @GetMapping("/ac-map/{userId}")
    public ZhimaOjResult getAcQuestionMap(@PathVariable("userId")Long userId) {
        return success(ojUserQuestionService.getAcQuestions(userId));
    }
}
